package com.example.teacher

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.example.teacher.adapter.DetailInfoAdapter
import com.example.teacher.data.SignInList
import com.example.teacher.data.Stusign
import com.example.teacher.databinding.ActivityDetailInfoBinding
import com.example.teacher.http.OkHttp
import com.example.teacher.util.JsonUtil

/**
 * 课堂签到，学生签到详细信息
 */
class DetailInfoActivity : AppCompatActivity() {

    lateinit var binding: ActivityDetailInfoBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_detail_info)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_detail_info)
        val courseId = intent.getStringExtra("courseId")
        val time = intent.getStringExtra("time")
        val courseName=intent.getStringExtra("courseName")

        binding.tvCourseId.text=courseId
        binding.tvCourseName.text=courseName
        binding.tvCoursetime.text=time


        val resData = OkHttp.getSync(
            "${BaseUrl.URL}${BaseUrl.GET_SIGNINLIST_BY_COURSEID}" +
                    "?courseId=${courseId}" +
                    "&time=${time}"
        )
        val dataParse = JsonUtil.DataParse<SignInList>(resData)

        val listInfo = mutableListOf<Stusign>()
        for (i in dataParse.indices) {
            if (dataParse[i].address == null) {
                dataParse[i].address = "未获取到位置"
            }
            val list = Stusign(
                dataParse[i].stuId.toString(),
                dataParse[i].name,
                dataParse[i].status,
                dataParse[i].address
            )
            listInfo.add(list)
        }
        val infoAdapter = DetailInfoAdapter(this, R.layout.detailinfo_item, listInfo)
        binding.detailInfoList.adapter = infoAdapter
    }
}